<template>
  <view class="type-box">
    <view class="type-arr">
      <view v-for="(item,index) in itemArr" :key="index" @click="change(item, index)" class="type-item" :class="[itemIndex == index ? 'active' : '',]">{{item}}</view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        itemArr: [ "基础命盘", "大运流年", "命盘解读" ],
        itemIndex: 0
      }
    },
    methods: {
      change(item, index) {
        if (index == this.itemIndex) return
        this.itemIndex = index;
        this.$emit('itemClick', {item, index});
      }
    }
  }
</script>

<style lang="scss" scoped>
  .type-box {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: center;
    background-color: #c5a680;
    padding: 20rpx 0;
    box-sizing: border-box;
    position: sticky;
    top: calc(env(safe-area-inset-top));
    z-index: 997;
  }
  .type-arr {
    width: 618rpx;
    height: 50rpx;
    background-color: #fff;
    border-radius: 40rpx;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    margin: 0 auto;
  }
  .type-item {
    color: #787878;
    font-weight: bold;
    width: 33%;
    height: 100%;
    border-radius: 40rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
  }
  .active {
    color: #FFFFFF;
    background-color: #4B240D;
  }
</style>